package br.ufc.ck0017.flowgraph;
import br.ufc.ck0017.graph.*;
import br.ufc.ck0017.temp.*;

/**
 * Created by Marcel on 28/06/2015.
 */
public abstract class FlowGraph extends Graph{
    /**
     * The set of temporaries defined by this instruction or block
     */
    public abstract TempList def(Node node);

    /**
     * The set of temporaries used by this instruction or block
     */
    public abstract TempList use(Node node);

    /**
     * True if this node represents a <strong>move</strong> instruction,
     * i.e. one that can be deleted if def=use.
     */
    public abstract boolean isMove(Node node);

    /**
     * Print a human-readable dump for debugging.
     */
    public void show(java.io.PrintStream out) {
        for (NodeList p=nodes(); p!=null; p=p.tail) {
            Node n = p.head;
            out.print(n.toString());
            out.print(": ");
            for(TempList q=def(n); q!=null; q=q.tail) {
                out.print(q.head.toString());
                out.print(" ");
            }
            out.print(isMove(n) ? "<= " : "<- ");
            for(TempList q=use(n); q!=null; q=q.tail) {
                out.print(q.head.toString());
                out.print(" ");
            }
            out.print("; goto ");
            for(NodeList q=n.succ(); q!=null; q=q.tail) {
                out.print(q.head.toString());
                out.print(" ");
            }
            out.println();
        }
    }

}
